package pl.edu.agh.xls2html.htmlelements;

import java.util.ArrayList;

import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

public class Table implements HTMLelement {

	private ArrayList<Row> rows;

	private int columnsNum = 0;
	private int rowsNum = 0;
	private HSSFWorkbook wb;

	public Table(HSSFSheet s, HSSFWorkbook wb, Document doc) {
		this.wb = wb;
		rowsNum = s.getLastRowNum() + 1;
		if (s.getRow(0) == null)
			rowsNum = 0;

		rows = new ArrayList<Row>();

		for (int i = 0; i < rowsNum; i++) {
			Row r = new Row(s.getRow(i), this.wb, doc);
			if (r.getRowLength() > columnsNum)
				columnsNum = r.getRowLength();
			rows.add(r);
		}

	}

	@Override
	public String getHTML() {
		String content = "";

		for (Row r : rows)
			content += r.getHTML();

		return HTMLHelper.makeTable(content);
	}

	@Override
	public String getCSS() {
		String css = "";
		for (Row r : rows)
			css += r.getCSS();
		return css;
	}

	public int getColumnsNum() {
		return columnsNum;
	}

	public int getRowsNum() {
		return rowsNum;
	}

}
